import axios from 'axios'
// 导入toast
import Toast from 'vant';
import store from '@/store';
const _axios = axios.create({
    baseURL: process.env.VUE_APP_URL
})

// 请求拦截
_axios.interceptors.request.use(config => {
    console.log(config);
    if (!config.noToken) {
        config.headers.Authorization = `Bearer ${store.getters['user/getToken']}`
    }
    return config
}, error => {
    return Promise.reject(error)
})
// 响应拦截
_axios.interceptors.response.use(res => {
    return res.data
}, error => {
    if (error.response.data && error.response.data.message) {
        Toast.fail(error.response.data.message)
    }
    console.log([error]);
    return Promise.reject(error)
})

export default _axios